package com.eptok.gw.szcups.service;

import org.dom4j.Document;

import ys8583.parse.IOMessage;

import com.eptok.gw.szcups.cups.CupsMessageControl;
import com.eptok.gw.szcups.cups.message.PackMessageUtil;
import com.eptok.gw.szcups.pojo.CancelCardPay;
import com.eptok.gw.szcups.pojo.XmlMessage;
import com.eptok.gw.szcups.socket.client.factory.ClientFactory;
import com.eptok.gw.szcups.util.SerialNumber;

/**
 * 消费退货
 * @author guoq
 *
 */
public class ReturnCardPayService  extends BaseService{
	
	
	public ReturnCardPayService(){
	}

	@Override
	public IOMessage process(XmlMessage xmlMessage) throws Exception {
		log.debug("ReturnCardPayService process start");
		CancelCardPay pay = (CancelCardPay)xmlMessage;
		IOMessage iomessagereq = PackMessageUtil.packReturnCardPay(pay);
		long id = this.insertlog(pay, iomessagereq);
		
		ClientFactory.getInstance().sendMessage(CupsMessageControl.CHAN_CLIENT_KEY, iomessagereq);
		IOMessage iomessagersp = CupsMessageControl.getInstance().getChanMessageRsp((String)iomessagereq.getRspField(11));
		if(iomessagersp == null){
			//消费退货无冲正,超时后直接返回超时 
			pay.setStatus("Z2");
			pay.setRspSerialNumber(SerialNumber.seqno());
		}else{
			pay.setStatus((String)iomessagersp.getReqMesField(39));
			pay.setRspSerialNumber(SerialNumber.seqno());
		}
		this.updatelog(id, pay, iomessagersp);
		log.debug("ReturnCardPayService process end");
		return iomessagersp;
	}


}
